#include <stdio.h>
#include <stdlib.h>

struct stack {
	int value;
	struct stack *next;
	struct stack *prev;
};

struct stack List;
struct stack *insert_now = &List;

struct stack * search_value(int x)
{
	struct stack *temp = List.next;
	while(temp != NULL)
	{
		if(temp->value == x)
		{
			return temp;
		}
		temp = temp->next;
	}
	return NULL;
}

void insert()
{
	struct stack *temp = (struct stack *)malloc(sizeof(struct stack));
	scanf("%d",&temp->value);
	insert_now->next = temp;
	temp->next = NULL;
	temp->prev = insert_now;
	insert_now = temp;
}

void search()
{
	int x;
	scanf("%d",&x);
	if(search_value(x) != NULL)
		printf("true\n");
	else 
		printf("false\n");
}

void delete()
{
	int x;
	scanf("%d",&x);
	struct stack * temp = search_value(x);
	if(temp == NULL)
	{
		printf("nothing has delete\n");
		return;
	}
	if(temp == insert_now)
	{
		insert_now = insert_now->prev;
		temp->prev->next = NULL;
	}
	else 
	{
		temp->prev->next = temp->next;
		temp->next->prev = temp->prev;
	}
	free(temp);
}

void menu()
{
	printf("1.insert\t\t2.search\n");
	printf("3.delete\t\t0.exit\n");
	printf("Please enter:");
}

int main()
{
	int selection;
	insert_now->next = NULL;
	insert_now->prev = NULL;
	insert_now->value = 0;
	while(1) 
	{
		menu();
		scanf("%d",&selection);
		switch(selection)
		{
		case 1:
			insert();
			break;
		case 2:
			search();
			break;
		case 3:
			delete();
			break;
		case 0:
			return 0;
		}
	}
	return 0;
}
